<?php
use yii\helpers\Url;

$web = Url::base();
$integral_unit = \app\models\Mall::getCurrentInstitutionIntegralUnit();
$site_name = \app\models\Mall::getCurrentInstitutionSiteName();
$institution_code = \app\models\Mall::getCurrentInstitutionCode();
$this->title = $site_name.'->我的积分';
?>
<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall/user-account-record.css"/>
<link rel="stylesheet" type="text/css" href="<?= $web ?>/css/mall/laydate.css"/>
<script src="<?= $web ?>/js/mall/laydate.js" type="text/javascript" charset="utf-8"></script>

<script type="application/javascript">

    function loadList(page) {
        var record_type = $("#record_type").val();
        var start_date = $("#start_date").val();
        var end_date = $("#end_date").val();

        var href = window.location.href;

        href = removeUrlParam(href,'page');
        href = removeUrlParam(href,'record_type');
        href = removeUrlParam(href,'start_date');
        href = removeUrlParam(href,'end_date');
        if (page > 0) {
            href = setUrlParam(href, 'page', page);
        }
        if (record_type != '' && record_type != null) {
            href = setUrlParam(href, 'record_type', record_type);
        }
        if (start_date != '' && start_date != null) {
            href = setUrlParam(href, 'start_date', start_date);
        }
        if (end_date != '' && end_date != null) {
            href = setUrlParam(href, 'end_date', end_date);
        }
        window.location.href = href;

    }

    function filter() {
        loadList(0);
    }

    function prePage() {
        var currentPage = $("#txtCurrentPage").val();
        if (currentPage != null && currentPage != '' && currentPage > 1) {
            currentPage--;
            loadList(currentPage);
        }
    }

    function nextPage() {
        var max_page = $("#hidden_max_page").val();
        var currentPage = $("#txtCurrentPage").val();
        if (currentPage != null && currentPage != '' && currentPage < max_page) {
            currentPage++;
            loadList(currentPage);
        }
    }

    function setRecordType(type) {
        $("#record_type").val(type);
        loadList(0);
    }
</script>
<style type="text/css">
    .my-information .data .sort .listbox .query input[type="button"]{
        background: url(<?= $web ?>/images/mall/big-img.png) no-repeat;
    }
    .my-information .data .sort .listbox .query input[type="button"]:hover{
        background: url(<?= $web ?>/images/mall/big-img1.png) no-repeat;
    }
</style>
<div class="my-information">
    <div class="menu fl">
        <ul>
            <li><a href="user-information?institution_code=<?= $institution_code ?>">个人信息</a></li>
            <li><a href="user-card?institution_code=<?= $institution_code ?>">我的卡卷</a></li>
            <li><a href="user-present?institution_code=<?= $institution_code ?>"><?= $integral_unit ?>转赠</a></li>
            <li><a href="order-list?institution_code=<?= $institution_code ?>">我的订单</a></li>
            <li><a href="javascript:void(0)" class="cur">我的<?= $integral_unit ?></a></li>
            <li><a href="user-address?institution_code=<?= $institution_code ?>">收货地址</a></li>
        </ul>
    </div>
    <div class="data fl">
        <div class="title">
            <p>我的<?= $integral_unit ?></p>
        </div>
        <div class="sort">
            <div class="listbox">
                <div class="all fl">
                    <ul>
                        <a href="javascript:void(0)">
                            <li class="<?php if ($record_type == null || $record_type == '' || $record_type == 0) echo 'cur'; ?>"
                                onclick="setRecordType(0)">全部
                            </li>
                        </a>
                        <a href="javascript:void(0)">
                            <li class="<?php if ($record_type != null && $record_type != '' && $record_type == 1) echo 'cur'; ?>"
                                onclick="setRecordType(1)">收入
                            </li>
                        </a>
                        <a href="javascript:void(0)">
                            <li class="<?php if ($record_type != null && $record_type != '' && $record_type == 2) echo 'cur'; ?>"
                                onclick="setRecordType(2)">支出
                            </li>
                        </a>
                    </ul>
                </div>
                <div class="query fl">
                    <input id="start_date" class="laydate-icon" type="text" placeholder="按时间查询" onclick="laydate()"
                           value="<?= $start_date ?>"/>
                    <span>-</span>
                    <input id="end_date" class="laydate-icon" type="text" placeholder="按时间查询" onclick="laydate()"
                           value="<?= $end_date ?>"/>
                    <input type="button" onclick="filter()" value=""/>
                </div>
                <div class="ncome fr">
                    <p><?= $integral_unit ?>余额：<span><?= number_format($userintegral) ?></span></p>
                </div>
            </div>
            <div class="check">
                <?php
                if ($items != null) {
                    $date_count = count($items);
                    for ($i = 0; $i < $date_count; $i = $i + 2) {
                        ?>
                        <div class="check-1">
                            <?php
                            if ($date_count > $i) {
                                $data0 = $items[$i];
                                ?>
                                <ul class="fl">
                                    <li><?= $data0['remark'] ?></li>
                                    <li class="<?php if ($data0['integral'] > 0) echo 'green'; ?>"><?= number_format($data0['integral']) ?>
                                        <?= $integral_unit ?>
                                    </li>
                                    <li><?= $data0['create_datetime'] ?></li>
                                </ul>
                                <?php
                            }
                            if ($date_count > $i + 1) {
                                $data1 = $items[$i + 1];
                                ?>
                                <ul class="fl">
                                    <li><?= $data1['remark'] ?></li>
                                    <li class="<?php if ($data1['integral'] > 0) echo 'green'; ?>"><?= number_format($data1['integral']) ?>
                                        <?= $integral_unit ?>
                                    </li>
                                    <li><?= $data1['create_datetime'] ?></li>
                                </ul>
                                <?php
                            }
                            ?>
                        </div>
                        <?php
                    }
                }
                ?>
                <input id="record_type" type="hidden" value="<?= $record_type ?>"/>
                <input id="hidden_max_page" type="hidden" value="<?= $max_page ?>"/>
                <div class="paging">
                    <p class="">总共<span><?= $max_page ?></span>页</p>
                    <div class="rank"><span>第</span><input class="num" id="txtCurrentPage" type="number" min="1"
                                                           max="<?= $max_page ?>"
                                                           value="<?= $page ?>"/><span>页</span></div>
                    <input id="btnPre" class="prev" onclick="prePage()" type="button" value="上一页"/>
                    <input id="btnNext" class="next" onclick="nextPage()" type="button" value="下一页"/>
                </div>
            </div>
        </div>
    </div>
</div>